package nl.saxion.security.connection;

import java.io.IOException;
import java.net.ServerSocket;

/**
 * Class for setting up Serverconnection
 * @author EII7SCb
 *
 */
public class ServerConnection extends Connection {
	
	private ServerSocket serverSocket = null;
	
	/**
	 * 
	 * @param port
	 */
	public ServerConnection(int port, int timeOut)
	{
		super(port, timeOut);
	}

	
	/**
	 * Start the server
	 * @return True if connected 
	 * @throws IOException 
	 */
	public boolean makeConnection() throws IOException 
	{
		serverSocket = new ServerSocket(port);
		connection = serverSocket.accept();
		//super.makeConnection();
		out = connection.getOutputStream();
		out.flush();
		in = connection.getInputStream();
		
		return true;
	}
	
	/**
	 * close connection
	 */
	public void close() throws IOException
	{
		in.close();
		out.close();
		connection.close();
		serverSocket.close();
	}
}
